package com.dwxt.community.service;

import com.dwxt.common.base.BaseResult;
import com.dwxt.common.util.MD5Utils;
import com.dwxt.common.util.OkHttpUtils;
import com.dwxt.community.dao.UserMapper;
import com.dwxt.community.entity.User;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class FangHuiService {

    @Autowired
    private UserMapper userMapper;

    public BaseResult register(String id) {
        User user = userMapper.selectByPrimaryKey(id);
        String username = user.getPhone();
        String password = user.getPassword();
        String url = "http://sz.wisdudu.com/sdk/index.php";
        Map params = new HashMap();
        params.put("appid", "153C7FFFCFAD35B2");
        params.put("appsecret", "800ED50033F740432FB247516DDFD7FD");
        params.put("method", "manage.user.info");
        params.put("username", username);
        params.put("pwds", password);
        String res = OkHttpUtils.formPost(url, params, null);
        JSONObject result = JSONObject.fromObject(res).getJSONObject("result");
        result.put("fangHuiId", username + "," + password);
        user.setFangHuiId(username + "," + password);
        userMapper.updateByPrimaryKeySelective(user);
        return BaseResult.ok(result);
    }
}
